﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Data.Entity;
using Proggy.Data.Concrete;
using Proggy.Web.Cms.AppHelpers;
using Proggy.Web.Cms.Core.Configuration;
using Proggy.Web.Cms.PropertyTypes;
using Proggy.Web.Cms.Core.ModelBinding;
using Proggy.Web.Cms.Core.ViewModels;
using Proggy.Web.Cms.ExampleDomain.Seeding;
using Proggy.Web.Cms.Core;

namespace Proggy.Web.Cms.Ui
{
    /// <summary>
    /// This is the main global class which inherits from ProggyHttpApplication
    /// Some "spaces" are left for you to do your own app-startup stuff. Some things must
    /// be left in place, otherwise the application will not run. This is made clear via
    /// the comments.
    /// </summary>
    public class MvcApplication : ProggyHttpApplication
    {
        /// <summary>
        /// Add stuff here if you want
        /// </summary>
        public override void ProggyApplicationStart()
        {
            // DEV ONLY - REMOVE IN PRODUCTION!!
            this.dropDbAndSeed();




            // MANDATORY - DO NOT REMOVE!!
            // CORE APP START PROCEDURE - ALWAYS BEFORE CORE STUFF
            base.ProggyApplicationStart();
            // ***** THIs IS MANDATORY IF YOU ARE USING PROGGY.WEB.CMS.CORE ****//
            // ***** NOTE, IF YOU ARE NOT USING "CORE", THEN YOU PROBABLY SHOULD BE!! ****//
            ProggyCoreManager.Instance.ProggyCoreApplicationStart(this); 
            
        }

        
        /// <summary>
        /// REMOVE ON REALEASE!!!
        /// </summary>
        private void dropDbAndSeed()
        {
            // choose whatever initializer you want here
            Database.SetInitializer<ProggyDataContext>(new ExampleSeed());

            // leave this
            var dc = new ProggyDataContext();

            // leave this
            dc.Database.Initialize(true);

        }

    }
}